package managesystem;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class VerifyStudentServlet extends HttpServlet{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1391432054378224714L;

	public void doPost(HttpServletRequest req, HttpServletResponse resp){
		
		String password = req.getParameter("password");
		String un = req.getParameter("username");
		HttpSession session = req.getSession(true);
		boolean succes = SM.get().verifyLogin(un,password);
		if(succes){
			
			session.setAttribute("currStud",SM.get().getCurrStud());
			try {
				resp.sendRedirect("/index.jsp");
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		else{
			try {
				session.setAttribute("error","Login failed ! Check your credentials");
				resp.sendRedirect("index.jsp");
			} catch (IOException e){
				e.printStackTrace();
			}
		}
		
	}

}
